package com.blb.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.ssm.entity.Menu;
import com.blb.ssm.entity.Role;
import com.blb.ssm.entity.RoleMenu;
import com.blb.ssm.mapper.RoleMapper;
import com.blb.ssm.service.IRoleMenuService;
import com.blb.ssm.service.IRoleService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author huahao
 * @since 2019-01-15
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

	@Autowired
	private IRoleMenuService roleMenuService;
	
	@Override
	public void setMenu(String id, List<Menu> menus) {
		roleMenuService.remove(new QueryWrapper<RoleMenu>(new RoleMenu()).eq("role_id", id));
		
		for (Menu menu : menus) {
			RoleMenu roleMenu = new RoleMenu();
			roleMenu.setRoleId(id);
			roleMenu.setMenuId(menu.getId());
			roleMenuService.save(roleMenu);
		}
	}

}
